package com.leetcode;

import java.util.ArrayList;
import java.util.List;

public class LeetCode830 {
    public List<List<Integer>> largeGroupPositions(String S) {

        int length = S.length();

        if (!(1 <= length && length <= 1000)) {
            return new ArrayList<List<Integer>>();
        }

        List<List<Integer>> result = new ArrayList<List<Integer>>();
        for (int i = 0; i < length; i++) {
            for (int j = i + 1; j < length; j++) {
                List<Integer> integerList = new ArrayList<Integer>();
                if (S.charAt(i) != S.charAt(j)) {
                    if (j - i <= 2) {
                        break;
                    }
                    integerList.add(i);
                    integerList.add(j - 1);
                    result.add(integerList);
                    i = j - 1;
                    break;
                }

                if (j == length - 1 && j - i >= 2) {
                    integerList.add(i);
                    integerList.add(length - 1);
                    result.add(integerList);
                    return result;
                }
            }
        }

        return result;
    }

    public static void main(String[] args) {
        LeetCode830 demo1 = new LeetCode830();
        List<List<Integer>> result = demo1.largeGroupPositions("babaaaabbb");
        System.out.println(result);
    }
}
